package lcweekfight.w_384;

public class Code03 {
    public static int numberOfSequence(int n, int[] sick) {
        int s = Integer.MAX_VALUE;
        s <<= n;
        s -= 1<<31;
        for(int i = 0;i < sick.length;i++){
            s += (1 << sick[i]);
        }
      return  sick.length > 1 ? process(s,n,0) / 2 : process(s,n,0);
    }
    public static int  process(int s,int n,int w){
        if(s == Integer.MAX_VALUE){
            return 1;
        }
        //情况1： 1左边是0 可感染 情况2：1左边是1 不可感染
        //情况3： 1右边是0 可感染 情况4: 1右边是1 不可感染
        //需要判断长度 0-n - 1
        int ways = 0;
        for(int i = 0;i < n;i++){
            if((s & (1 << i)) == (1 <<i)){
                if(i != 0){
                    if((s & (1 << (i - 1))) != (1 <<(i - 1))){
                        s += (1 << (i - 1));
                         //ways++;
                        ways += process(s,n,w);
                        s -= (1 << (i - 1));
                    }
                }
                if((s & (1 << (i + 1))) != (1 <<(i + 1))){
                    s += (1 << (i + 1));
                     //ways++;
                    ways += process(s,n,w);
                    s -= (1 << (i + 1));
                }
            }
        }
        return ways;
    }

    public static void main(String[] args) {
        int[] sick = new int[]{0,4};
        int n = 5;
        System.out.println(numberOfSequence(5,sick));
    }
}
